import { Controller } from "../../mvc/core/Controller";
import { Dispatcher } from "../../mvc/core/Dispatcher";
import { EventName } from "../mvc/EventName";
import { NetDispatcher } from "../../mvc/core/NetDispatcher";
import { ServerCommand } from "../mvc/ServerCommand";
import { OlympicGuessIconView } from "../view/olympic/OlympicGuessIconView";
import { DataEvent } from "../events/DataEvent";
import { EActiveType } from "../../../Message/Public/EActiveType";
import { OlympicModule } from "../../../modules/OlympicModule";
import { GameProxy } from "../mvc/GameProxy";
import { SPlayerOlympicGuessInfo } from "../../../Message/Game/SPlayerOlympicGuessInfo";
import { OlympicGuessData } from "../view/olympic/data/OlympicGuessData";
//class OlympicController
    
    export  class OlympicController extends Controller
    {
       

        protected /* override */ initServer(): void
        {
            Dispatcher.addEventListener(EventName.AcitveTimeUpdate, this.onAcitveTimeUpdateHandler);
            Dispatcher.addEventListener(EventName.OlympicGuessClickOpen, this.clickOpenGuessHandler);
            NetDispatcher.addCmdListener(ServerCommand.OlympicGuessDataUpdate, this.guessDataUpdateHandler);
            Dispatcher.addEventListener(EventName.OlympicGuessResFileGot, this.guessGotResFileHandler);
            Dispatcher.addEventListener(EventName.OlympicSubmitTodayGoldNum, this.guessTodayGoldNumHandler);
            Dispatcher.addEventListener(EventName.OlympicSubmitMostGoldNumCountry, this.guessMostGoldCountryHandler);
            Dispatcher.addEventListener(EventName.OlympicClickExpandTodayGusess, this.clickExpandTodayGuessItemHandler);
            Dispatcher.addEventListener(EventName.OlympicGuessClickChangeTab, this.guessClickChangeTabHandler);
            Dispatcher.addEventListener(EventName.OlympicGuessExpandGuessingItem, this.guessItemExpandHandler);
            Dispatcher.addEventListener(EventName.OlympicGuessShrinGuessingItem, this.guessItemShrinHandler);
            return;
        }

        public get iconView(): OlympicGuessIconView
        {
            if (this._iconView == null) 
            {
                this._iconView = new OlympicGuessIconView();
            }
            return this._iconView;
        }

        /* internal  */onAcitveTimeUpdateHandler(arg1: DataEvent): void
        {
            var loc1=cache.active.isActiveInEffect(EActiveType._EActiveTypeOlympicGuess);
            if (loc1) 
            {
                this.iconView.show();
            }
            else if (this._iconView) 
            {
                this._iconView.hide();
            }
            return;
        }

        /* internal  */clickOpenGuessHandler(arg1: DataEvent): void
        {
            if (this._module == null) 
            {
                this._module = new OlympicModule();
            }
            GameProxy.daily.getOlympicGuess();
            this._module.showPredictWindow();
            return;
        }

        /* internal  */guessGotResFileHandler(arg1: DataEvent): void
        {
            if (cache.olympicGuess.data != null) 
            {
                this._module.updateGuessTodayData(cache.olympicGuess.data);
            }
            this._module.showPredictWindow();
            return;
        }

        /* internal  */guessDataUpdateHandler(arg1: Object): void
        {
            if (this._module == null) 
            {
                return;
            }
            this._module.updateGuessTodayData(cache.olympicGuess.data);
            return;
        }

        /* internal  */test(arg1: DataEvent): void
        {
            var loc1=new SPlayerOlympicGuessInfo();
            loc1.myType1 = new Map<any, any> /* flash.utils.Dictionary */();
            loc1.type1Result = new Map<any, any> /* flash.utils.Dictionary */();
            loc1.myType1[1] = 1;
            loc1.type1Result[1] = 3;
            loc1.myType1[2] = -1;
            loc1.type1Result[2] = 20;
            loc1.myType1[3] = 2;
            loc1.type1Result[3] = 20;
            loc1.myType1[4] = -1;
            loc1.type1Result[4] = -1;
            var loc2=5;
            while (loc2 < 17) 
            {
                loc1.myType1[loc2] = -1;
                loc1.type1Result[loc2] = -1;
                ++loc2;
            }
            loc1.myType3Int = -1;
            loc1.type3ResultInt = -1;
            this._module.updateGuessTodayData(loc1);
            return;
        }

        /* internal  */guessTodayGoldNumHandler(arg1: DataEvent): void
        {
            var loc1=int(arg1.data);
            GameProxy.daily.olympicDailyGuess(loc1);
            return;
        }

        /* internal  */guessMostGoldCountryHandler(arg1: DataEvent): void
        {
            var loc1=int(arg1.data);
            GameProxy.daily.olympicMostGoldNum(loc1);
            return;
        }

        public clickExpandTodayGuessItemHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data as OlympicGuessData;
            this._module.expandGuessTodayItem(loc1);
            return;
        }

        /* internal  */guessClickChangeTabHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data as string;
            this._module.changeGuessTab(loc1);
            return;
        }

        /* internal  */guessItemExpandHandler(arg1: DataEvent): void
        {
            this._module.changeAnswerTipsToExpandType();
            return;
        }

        /* internal  */guessItemShrinHandler(arg1: DataEvent): void
        {
            this._module.changeAnswerTipsToShrinType();
            return;
        }

        private /* var */_module: OlympicModule;

        private /* var */_iconView: OlympicGuessIconView;
    }
